import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User: 花海
 * Date: 2022-09-11
 * Time: 12:01
 */
public class sqlist <T extends Number>{
        T[]arr;
    private int size;
    private int capacity;
    sqlist(){
         capacity=3;
         size=0;
       arr=(T[])new Number[capacity];

    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }
    boolean isfull(){
        if(getSize()>=getCapacity())
            return true;
        return false;

    }
    void IncreaseCapitacity(){
        if(isfull()){
            arr= Arrays.copyOf(arr,getSize()*2);

        }


        }
        void AddSqlist(T num,int location){
        if(location<0||location>=capacity){
            throw new poswrongfulException("location is worong");


        }else{
            size++;
            IncreaseCapitacity();
            for(int i=size-1;i>=location;i--){
                arr[i+1]=arr[i];

            }
            arr[location]=num;

        }



        }
        void DecreaseSqlist(int location){
            if(location<0||location>=capacity){
                throw new poswrongfulException("location is wrong");


            }else{
                size--;
                IncreaseCapitacity();

                for(int i=location;i<size;i++){
                    arr[i]=arr[i+1];

                }



                }

        }
        void DisplaySqlist(){
            for (int i = 0; i < size; i++) {
                System.out.println(arr[i]+" ");
            }
        }

    public static void main(String[] args) {
        sqlist sq=new sqlist<Integer>();
        try{

            sq.AddSqlist(1,0);
            sq.AddSqlist(99,1);
            sq.AddSqlist(3,2);
            sq.DecreaseSqlist(0);
            sq.DisplaySqlist();

        }catch(poswrongfulException e){
            e.printStackTrace();
        }

    }
    }



